package com.example.udpsender;

import android.os.Bundle;
import android.app.Activity;
import android.content.*;
import android.view.*;
import android.widget.Button;
import android.widget.Toast;
import android.view.View;

import java.io.IOException;
import java.lang.String;
import java.net.DatagramSocket;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.lang.Exception;
import java.net.SocketException;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setUpSocket();
		setContentView(R.layout.activity_main);
		Button actiony = (Button)findViewById(R.id.ButtonActionY);
		actiony.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub

				UdpSenderTask mytask = new UdpSenderTask();
				switch(event.getAction())
				{
				case	MotionEvent.ACTION_DOWN:
				{
					mytask.execute(JoyStickEnum.BUTTON_INDEX_ACTION_Y_DOWN);
					break;
				}
				case MotionEvent.ACTION_UP:
				{
					mytask.execute(JoyStickEnum.BUTTON_INDEX_ACTION_Y_UP);
				}
					break;
				}
				
				return false;
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	@Override
	public void onStop()
	{
		super.onStop();
	}

	public void butUpClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_UP);
	}
	
	public void butLeftClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_LEFT);
	}
	
	public void butDownClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_DOWN);
	}
	
	public void butRightClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_RIGHT);
	}
	
	public void butActionAClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_ACTION_A);
	}
	
	public void butActionBClicked(View view) throws Exception
	{
		UdpSenderTask mytask = new UdpSenderTask();
		mytask.execute(JoyStickEnum.BUTTON_INDEX_ACTION_B);
	}
}
